import request from "@/store/request";
import requests from "./request";

import store from "@/store";

export const getDefaultRoomAPI = () =>
  requests({
    url: "/my/getdefaultroom",
    method: "get",
  });

// 获取用户当前所在的房间
export const getCurrentRoomAPI = () =>
  requests({
    url: "/my/getcurrentroom",
    method: "get",
  });
/**
 *
 * @returns Promise 获取我创建的房间
 */
export const getMyCreateRoomsAPI = () =>
  requests({
    url: "/my/getmycreaterooms",
    method: "get",
  });

/**
 *
 * @returns 获取所有的房间信息
 */
export const getAllRoomsAPI = () =>
  requests({
    url: "/my/getallrooms",
    method: "get",
  });

/**
 * params
 * @returns 获取我的所有房间===type 1 为我创建的 0 为我加入的
 */
export const getMyRoomsAPI = (type) =>
  requests({
    url: "/my/getmyrooms",
    method: "get",
    params: {
      type,
    },
  });

/**
 *创建房间
 * @param {  name avatar info} param0
 * @returns
 */
export const createRoomAPI = ({ name, avatar, info, author_name }) =>
  requests({
    url: "/my/createroom",
    method: "post",
    data: {
      name,
      avatar,
      info,
      author_name,
    },
  });

/**
 * 加入房间
 * @param {room_id 房间ID avatar  房间头像 , name 房间名，author_id房间作者id}} param0
 * @returns
 */
export const joinRoomAPI = ({ room_id, avatar, name, author_id }) =>
  requests({
    url: "/my/joinroom",
    method: "post",
    data: {
      room_id,
      avatar,
      name,
      author_id,
    },
  });

export const deleteUserAPI = (user_id, room_id) =>
  requests({
    url: "/my/deleteuser",
    method: "post",
    params: {
      user_id,
      room_id,
    },
  });
/**
 *跟新目前用户所在房间的状权 isInRoom 全为0
 * @returns
 */
export const updateRoomIsInRoomAPI = (room_id) =>
  requests({
    url: "/my/updateroomisinroom",
    method: "post",
    params: {
      room_id,
    },
  });

/**
 * 点击切换房间 将该房间的用户状态改为 1 表示在这个房间里面
 * @param {room_id} room_id
 * @returns
 */
export const checkRoomAPI = (room_id) =>
  requests({
    url: "/my/checkroom",
    method: "post",
    params: {
      room_id,
    },
  });

/**
 *退出群聊
 * @param {退出群聊的房间ID} room_id
 * @returns
 */
export const leaveMyRoomAPI = (room_id) =>
  requests({
    url: "/my/leavemyroom",
    method: "post",
    params: {
      room_id,
    },
  });

/**
 *解散群聊
 * @param {解散群聊的房间ID} room_id
 * @returns
 */
export const deleteRoomAPI = (room_id) =>
  requests({
    url: "/my/deleteroom",
    method: "post",
    params: {
      room_id,
    },
  });

//聊天
// export const chatAPI = () =>
//   requests({
//     url: "/my/chat",
//     method: "get",
//   });

/**
 * 获取当前房间的所有消息
 * @param {room_id} room_id
 * @returns
 */
export const getMessageAPI = (room_id, page, pageSize) =>
  requests({
    url: "/my/getmessage",
    method: "get",
    params: {
      room_id,
      page,
      pageSize,
    },
  });

/**
 *
 * @param {模糊查询群信息} code 0 为按number 1 为按群名
 * @returns
 */
export const searchRoomAPI = (number, code) =>
  requests({
    url: "/my/serchroom",
    method: "get",
    params: {
      number,
      code,
    },
  });
/**
 *获取房间用户信息
 * @param {room_id 群里Id} room_id
 *
 * @returns
 */
export const getRoomUsersAPI = (room_id) =>
  requests({
    url: "/my/getroomusers",
    method: "get",
    params: {
      room_id,
    },
  });
